package com.kaifamiao.dao;

import com.model.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author lucien-ma
 * @date 2021/8/31
 * @apiNote
 */
@Repository("accountDao")
public class AccountDao{

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public Account findById(Integer id) {
        return jdbcTemplate.queryForObject("select * from account where id = ?",
                new BeanPropertyRowMapper<>(Account.class), id);
    }

    public int updateMoney(Integer id, Double money) {
        return jdbcTemplate.update("update account set money = money + (?) where id = ?",
                money, id);
    }
}
